﻿using RRQMXml;
using System.IO;

namespace DBController
{
    public class AppConfig
    {
        public AppConfig(string path)
        {
            if (File.Exists(path))
            {
                XmlTool xml = new XmlTool(path);
                this.ServiceIP = xml.SearchWords("ServiceIP", "value");
                this.FileServicePort = xml.SearchNumber("FileServicePort", "value");
                this.RPCServicePort = xml.SearchNumber("RPCServicePort", "value");
                this.FileServiceThreadCount = xml.SearchNumber("FileServiceThreadCount", "value");
                this.RPCServiceThreadCount = xml.SearchNumber("RPCServiceThreadCount", "value");
            }
            else
            {
                XmlTool xml = new XmlTool(path);
                xml.AttributeStorage("ServiceIP", "value", "127.0.0.1");
                xml.AttributeStorage("FileServicePort", "value", "7789");
                xml.AttributeStorage("RPCServicePort", "value", "7790");
                xml.AttributeStorage("FileServiceThreadCount", "value", "1");
                xml.AttributeStorage("RPCServiceThreadCount", "value", "1");
            }
        }

        /// <summary>
        /// 服务器IP
        /// </summary>
        public string ServiceIP { get; set; }

        /// <summary>
        /// 文件服务器端口号
        /// </summary>
        public int FileServicePort { get; set; }

        /// <summary>
        /// RPC服务器端口号
        /// </summary>
        public int RPCServicePort { get; set; }

        /// <summary>
        /// 文件服务器多线程线程数量
        /// </summary>
        public int FileServiceThreadCount { get; set; }

        /// <summary>
        /// RPC服务器线程数量
        /// </summary>
        public int RPCServiceThreadCount { get; set; }
    }
}